package com.degratnik.plitki.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class Helper extends SQLiteOpenHelper {

	  public static final String TABLE_EVENTS = "events";
	  // Columns
	  public static final String ID = "_id"; // unique id
	  public static final String TITLE = "title"; // event title
	  public static final String DETAILS = "details"; // event detail
	  public static final String IMAGE = "image"; // image file name
	  public static final String DATE = "date"; // date for event
	  public static final String REMINDER = "reminder"; // reminder for event
	  public static final String PRIORITY = "priority"; // event priority

	  private static final String DATABASE_NAME = "events.db";
	  private static final int DATABASE_VERSION = 7;

	  // Database creation sql statement
	  private static final String DATABASE_CREATE = "create table "
	      + TABLE_EVENTS + "(" 
		  + ID + " integer primary key autoincrement, "
	      + TITLE + " text not null, "
	      + DETAILS + " text not null, "
	      + IMAGE + " text not null, "
	      + DATE + " integer, "
	      + REMINDER + " integer, "
	      + PRIORITY + " integer);";

	  public Helper(Context context) {
	    super(context, DATABASE_NAME, null, DATABASE_VERSION);
	  }

	  @Override
	  public void onCreate(SQLiteDatabase database) {
	    database.execSQL(DATABASE_CREATE);
	  }

	  @Override
	  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	    Log.w(Helper.class.getName(),
	        "Upgrading database from version " + oldVersion + " to "
	            + newVersion + ", which will destroy all old data");
	    db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENTS);
	    onCreate(db);
	  }

	} 
